<?php
	//
	function resize_image($url,$maxWidth,$maxHeight,$destUrl){
		$imgSource =  imagecreatefromjpeg($url);
		$origWidth = imagesx($imgSource);
		$origHeight = imagesy($imgSource);
		$maxRatio = $maxWidth / $maxHeight;
		$ratioImg = $origWidth / $origHeight;
		//calcul de la nouvelle taille
		if($origWidth > $maxWidth || $origHeight > $maxHeight){
			if($ratioImg > $maxRatio){
				$newWidth = $maxWidth;
				$newHeight = ($maxWidth / $ratioImg);
			}else{
				$newHeight = $maxHeight;
				$newWidth = ($maxHeight * $ratioImg);
			}
		}
		//on crée la nouvelle image
		$imgDest = imagecreatetruecolor($newWidth,$newHeight);
		imagecopyresampled($imgDest,$imgSource,0,0,0,0,$newWidth,$newHeight,$origWidth,$origHeight);
		$ok = imagejpeg($imgDest,$destUrl);
		return($ok)?true:false;
	}
	//
?>